/*
 * Copyright (C) 2006  Antonie Struyk
 *
 * This file is part of MusicFlashCards.
 *
 *    Freetar Hero is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    MusicFlashCards is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with MusicFlashCards; if not, write to the Free Software
 *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
package com.antonstruyk.musicflashcards;

import java.util.List;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Random;

/**
 *
 * @author Anton
 */
public class RandomNoteGenerator {
    
    private List<Note> notesToChooseFrom;
    private Random random;
    
    /** Creates a new instance of NoteGenerator */
    public RandomNoteGenerator(Note[] notesToChooseFrom) {
        this.notesToChooseFrom = new ArrayList<Note>();
        for(Note n : notesToChooseFrom){
            this.notesToChooseFrom.add(n);
        }
        random = new Random();
    }
    
    public RandomNoteGenerator(Collection<Note> notesToChooseFrom){
        this.notesToChooseFrom = new ArrayList<Note>();
        for(Note n : notesToChooseFrom){
            this.notesToChooseFrom.add(n);
        }
        random = new Random();
    }
    
    public Note nextNote(){
        if(notesToChooseFrom.size() > 0){
            int randomIndex = (int) (random.nextFloat() * notesToChooseFrom.size());
            return notesToChooseFrom.get(randomIndex);
        }
        return null;
    }
    
    public void addNotes(Collection<Note> notes){
        for(Note n : notes){
            if(!notesToChooseFrom.contains(n)){
                notesToChooseFrom.add(n);
            }
        }
    }
    
    public void removeNotes(Collection<Note> notes){
        notesToChooseFrom.removeAll(notes);
    }
    
    public void addNotes(Note[] notes){
        for(Note n : notes){
            if(!notesToChooseFrom.contains(n)){
                notesToChooseFrom.add(n);
            }
        }
    }
    
    public void removeNotes(Note [] notes){
        for(Note n : notes){
            notesToChooseFrom.remove(n);
        }
    }
}
